package com.erms.lab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.erms.common.annotation.Log;
import com.erms.common.enums.BusinessType;
import com.erms.lab.domain.SysScience;
import com.erms.lab.service.ISysScienceService;
import com.erms.common.core.controller.BaseController;
import com.erms.common.core.domain.AjaxResult;
import com.erms.common.utils.poi.ExcelUtil;
import com.erms.common.core.page.TableDataInfo;

/**
 * 开展科普活动情况Controller
 * 
 * @author guo
 * @date 2020-03-22
 */
@Controller
@RequestMapping("/lab/science")
public class SysScienceController extends BaseController
{
    private String prefix = "lab/science";

    @Autowired
    private ISysScienceService sysScienceService;

    @RequiresPermissions("lab:science:view")
    @GetMapping()
    public String science()
    {
        return prefix + "/science";
    }

    /**
     * 查询开展科普活动情况列表
     */
    @RequiresPermissions("lab:science:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysScience sysScience)
    {
        startPage();
        List<SysScience> list = sysScienceService.selectSysScienceList(sysScience);
        return getDataTable(list);
    }

    /**
     * 导出开展科普活动情况列表
     */
    @RequiresPermissions("lab:science:export")
    @Log(title = "开展科普活动情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysScience sysScience)
    {
        List<SysScience> list = sysScienceService.selectSysScienceList(sysScience);
        ExcelUtil<SysScience> util = new ExcelUtil<SysScience>(SysScience.class);
        return util.exportExcel(list, "science");
    }

    /**
     * 新增开展科普活动情况
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存开展科普活动情况
     */
    @RequiresPermissions("lab:science:add")
    @Log(title = "开展科普活动情况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysScience sysScience)
    {
        return toAjax(sysScienceService.insertSysScience(sysScience));
    }

    /**
     * 修改开展科普活动情况
     */
    @GetMapping("/edit/{sciId}")
    public String edit(@PathVariable("sciId") Long sciId, ModelMap mmap)
    {
        SysScience sysScience = sysScienceService.selectSysScienceById(sciId);
        mmap.put("sysScience", sysScience);
        return prefix + "/edit";
    }

    /**
     * 修改保存开展科普活动情况
     */
    @RequiresPermissions("lab:science:edit")
    @Log(title = "开展科普活动情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysScience sysScience)
    {
        return toAjax(sysScienceService.updateSysScience(sysScience));
    }

    /**
     * 删除开展科普活动情况
     */
    @RequiresPermissions("lab:science:remove")
    @Log(title = "开展科普活动情况", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysScienceService.deleteSysScienceByIds(ids));
    }
}
